import pandas as pd
from prompt_constant import PROMPT
from myUtils import llm_client
from qwen3_client import Qwen3Client
# 磐智认证参数
appid = "dsjyybai"
appKey = "bb9c5100caf0f84e22d88451e94ce2bb"
capabilityname = "llmm"
headers = gen_proxy_header(appid, appKey, capabilityname)

# URL，办公网或呼池使用10.217.247.48，其它资源池请更换对应IP
base_url = "http://10.217.247.48:9050/llmm-prod/v1/chat/completions"
api_key = "cs-baac3b82" # "chatbi"
model = "qwen3-32b-hc"

messages=[{"role": "user","content": "hello, 介绍以下你自己"}]
llm_client = Qwen3Client(headers, base_url, api_key, model, messages)
# resp = client.chat(messages)

df = pd.read_excel('log_processor/query_20250516.xlsx')[:5]

df['sys_role'] = df.apply(lambda x: PROMPT+x['userTagAnalysis']+x['topElements']+x['questions'], axis=1)
df['qwen2.5-72b'] = df['history'].apply(lambda x: eval(x)[-1]['content'])
df['openFlag'] = df['history'].apply(lambda x:  len(eval(x)) == 1)
# df['qwen2.5-72b'] = df.apply(lambda x: '' if  x['openFlag'] else x['qwen2.5-72b'], axis=1)
df['messages'] = df.apply(lambda x: eval(x['history'])+[{"role": "user", "content": x['message']}], axis=1)
df = df[['dialogId', 'sys_role',  'history','openFlag', "messages","message",'qwen2.5-72b',]]
new_llm_resp = []
for x in df.iterrows():
    if x[1]['openFlag']:
        new_resp = x[1]['qwen2.5-72b']
    else:
        sys_role = x[1]['sys_role']
        messages = x[1]['messages'][:-2]
        try:
            messages = [{"role": "system", "content": sys_role}] + messages
            # new_resp = llm_client.chat(messages)
            # new_resp = new_resp.content
            new_resp = llm_client.chat(messages)
        except:
            new_resp = "error resp"
    new_llm_resp.append(new_resp)
df['qwen3-30b'] = new_llm_resp
df.to_excel('query_20250519_resp_2.5_vs_3.xlsx')
